<?php

if (!defined('NV_SYSTEM')) { die ("You can't access this file directly..."); }

$module_name = basename(dirname(__FILE__));
@require_once("mainfile.php");
if (file_exists("".$datafold."/".$module_name."_config.php")) {
	@require_once("".$datafold."/".$module_name."_config.php");
}
get_lang($module_name);
if (file_exists("".$datafold."/config_".$module_name.".php")) {
	@require_once ("".$datafold."/config_".$module_name.".php");
}
if (defined('_MODTITLE')) $module_title = _MODTITLE;
##########################################
$index=1;
$addnews = 0;//hien chua sua xong

if (file_exists("".$datafold."/ncatlist.php")) {
	@require_once ("".$datafold."/ncatlist.php");
}

function main() {
	global $nvcat, $nvcat2, $adminfold, $adminfile, $newspagenum, $home, $module_name, $linkshome, $sizecatnewshomeimg, $path, $catnewshomeimg, $catimgnewshome, $newshome, $adminfold, $db, $prefix, $multilingual, $currentlang, $articlecomm, $pagenum;
	if ($multilingual == 1) { $querylang = "AND (alanguage='$currentlang' OR alanguage='')"; } else { $querylang = ""; }
	include("header.php");
	automated_news();
	$mau = 0;
	if (($newshome == 1) AND ($home == 1)) {
	for ($nvc=0;$nvc < sizeof($nvcat);$nvc++) {
		if($nvcat[$nvc]!="") {
		$nvcat_ar = explode("|",$nvcat[$nvc]);
		if($nvcat_ar[1]=='0' && $nvcat_ar[5]=='1') {
			$cat_id = intval($nvcat_ar[0]);
			$cat_title = stripslashes(check_html($nvcat_ar[2], "nohtml"));
			$linkshome = intval($nvcat_ar[7]);
			$storieshome = intval($nvcat_ar[6]);
			$catimage = $nvcat_ar[4];
			$whe = "WHERE (catid='$cat_id'";
			$subcat = explode(",",$nvcat_ar[8]);
			for ($i=0;$i < sizeof($subcat);$i++) {
				if($subcat[$i]!="") {
					$nvcat2_ar = explode("|",$nvcat2[$subcat[$i]]);
					if($nvcat2_ar[5]==1) $whe .= "OR catid='".intval($subcat[$i])."'";
				}
			}
			$whe .= ")";
			if ($storieshome != 0) {
				$xstorieshome = $storieshome;
			} else {
				$liststhm = array();
				$m=0;
				for($n=0;$n < sizeof($subcat);$n++) {
					$nvcat2_ar2 = explode("|",$nvcat2[$subcat[$n]]);
					if($nvcat2_ar2[5]==1 AND $nvcat2_ar2[6]!='0') {
						$liststhm[$m] = intval($nvcat2_ar2[6]);
						$m++;
					}
				}
				rsort($liststhm);
				$xstorieshome = intval($liststhm[0]);
			}
			$numx = $db->sql_fetchrow($db->sql_query("SELECT COUNT(*) FROM ".$prefix."_stories WHERE ihome='1' AND sid='$xstorieshome' AND newsst!='1' $querylang"));
			if($numx[0]==1) {
				$result2 = $db->sql_query("SELECT * FROM ".$prefix."_stories WHERE sid='$xstorieshome'");
			} else {
				$result2 = $db->sql_query("SELECT * FROM ".$prefix."_stories $whe AND ihome='1' AND newsst!='1' $querylang ORDER BY sid DESC LIMIT 0,1");
			}
			if ($db->sql_numrows($result2) != 0) {
				$cat_name = "<a href=\"modules.php?name=$module_name&op=viewcat&catid=$cat_id\" class=\"storytitle\">$cat_title</a>";
				categoryname($cat_name);
				$row2 = $db->sql_fetchrow($result2);
				$sid = intval($row2['sid']);
				$aid = stripslashes($row2['aid']);
				$title = stripslashes(check_html($row2['title'], "nohtml"));
				$time = formatTimestamp($row2['time'],2);
				$hometext = stripslashes($row2['hometext']);
				$bodytext = stripslashes($row2['bodytext']);
				$images = $row2['images'];
				$comments = stripslashes($row2['comments']);
				$counter = intval($row2['counter']);
				$notes = stripslashes($row2['notes']);
				$acomm = intval($row2['acomm']);
				$imgtext = stripslashes(check_html($row2['imgtext'], "nohtml"));
				$source = stripslashes(check_html($row2['source'], "nohtml"));
				$topicid = intval($row2['topicid']);		
				if ($catimgnewshome == 1) {
    					if ($catimage == "") { $catimage = "AllTopics.gif"; }
    					if ($catnewshomeimg == "right") { $fl = "left"; }
    					if ($catnewshomeimg == "left") { $fl = "right"; }
					$size2 = @getimagesize("images/cat/$catimage");
    					$title = "<a href=\"modules.php?name=$module_name&op=viewcat&catid=$cat_id\" title=\"$cat_title\"><img border=\"0\" src=\"images/cat/$catimage\" width=\"$size2[0]\" style=\"float: $fl\"></a> <a href=\"modules.php?name=$module_name&op=viewst&sid=$sid\">$title</a>";
    				} else {
    					$title = "<a href=\"modules.php?name=$module_name&op=viewst&sid=$sid\">$title</a>\n";
    				}
				if ($bodytext != "") {
					$story_link = "<a href=\"modules.php?name=$module_name&op=viewst&sid=$sid\"><img src='images/more.gif' border='0' width=\"47\" height=\"9\" alt=\""._READMORE."\" align=\"right\"></a>";
				} else {
					$story_link = "";
				}
				$com_link = "";
				if (defined('IS_ADMMOD')) {
	    				$com_link .= " ("._COMMENTSQ.": $comments  | ";
					$tot_hits = ""._TOTHITS.": $counter | <a href=\"".$adminfold."/".$adminfile.".php?op=EditStory&sid=$sid\">"._EDIT."</a> | <a href=\"".$adminfold."/".$adminfile.".php?op=RemoveStory&sid=$sid\">"._DELETE."</a>)";
				}
				if ($images != "" AND file_exists("".$path."/".$images."")) {
					if(file_exists("".$path."/small_".$images."")) {
						$images = "small_".$images."";
					}
					$size2 = @getimagesize("$path/$images");
					$widthimg = $size2[0];
					if ($size2[0] > $sizecatnewshomeimg) { $widthimg = $sizecatnewshomeimg; }
					$xtitle = stripslashes(check_html($row2['title'], "nohtml"));
					$story_pic = "<table border=\"0\" width=\"$widthimg\" cellpadding=\"0\" cellspacing=\"3\" align=\"$catnewshomeimg\">\n<tr>\n<td>\n<a href=\"modules.php?name=$module_name&op=viewst&sid=$sid\"><img border=\"0\" src=\"$path/$images\" width=\"$widthimg\" alt=\"$xtitle\"></a></td>\n</tr>\n</table>\n";		
				} else {
					$story_pic = "";
				}
				$notes = "";
				$result3 = $db->sql_query("SELECT sid, time, title FROM ".$prefix."_stories $whe AND (ihome='1' AND sid!='$sid' AND newsst!='1') $querylang ORDER BY sid DESC LIMIT $linkshome");
				$num3 = $db->sql_numrows($result3);
				if ($num3 != 0) {
					$notes .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td style=\"text-align: justify\" valign=\"top\">\n";
					$notes .= "<p class=topmore style=\"margin-top: 5px; margin-bottom: 5px\">"._MORENEWS2."</p>";
	    				while ($row3 = $db->sql_fetchrow($result3)) {
	    					$sid3 = intval($row3['sid']);
						$title3 = stripslashes(check_html($row3['title'], "nohtml"));
						$time3 = formatTimestamp($row3['time'],2);
						$notes .= "<img src='images/modules/$module_name/arrow3.gif' border='0' width=\"10\"><a href='modules.php?name=$module_name&op=viewst&sid=$sid3' class=indexlink>$title3</a>  <font class=grey>[$time3]</font><br>";
	    				}
	    				$notes .= "</td></tr></table>";
				}
				
				themeindex($aid, $time, $title, $hometext, $story_pic, $notes, $story_link, $com_link, $tot_hits,$mau);
				$mau++;
    			}
    		}
    		}
	}
    } else {
    	$numf = $db->sql_fetchrow($db->sql_query("SELECT COUNT(*) FROM ".$prefix."_stories WHERE ihome='1' AND newsst!='1' $querylang"));
	$page = ( isset($_GET['page']) ) ? intval($_GET['page']) : 0;
	$all_page = ( $numf[0] ) ? $numf[0] : 1;
	$per_page = intval($newspagenum);
	$base_url = "modules.php?name=$module_name";
	if($numf[0] > 0) {
    	$result = $db->sql_query("SELECT * FROM ".$prefix."_stories WHERE (ihome='1' AND newsst!='1') $querylang ORDER BY sid DESC LIMIT $page,$per_page");
    	while ($row = $db->sql_fetchrow($result)) {
    		$sid = intval($row['sid']);
    		$catid = intval($row['catid']);
    		$aid = stripslashes($row['aid']);
    		$title = stripslashes(check_html($row['title'], "nohtml"));
    		$time = formatTimestamp($row['time'],2);
    		$hometext = stripslashes($row['hometext']);
    		$bodytext = stripslashes($row['bodytext']);
    		$images = $row['images'];
    		$comments = stripslashes($row['comments']);
    		$counter = intval($row['counter']);
    		$notes = stripslashes($row['notes']);
    		$acomm = intval($row['acomm']);
    		$imgtext = stripslashes(check_html($row['imgtext'], "nohtml"));
    		$source = stripslashes(check_html($row['source'], "nohtml"));
    		$topicid = intval($row['topicid']);
    		if ($catid > 0) {
    			$cat_inf = explode("|",$nvcat2[$catid]);
    			$cattitle = stripslashes(check_html($cat_inf[2], "nohtml"));
    			$catimage = $cat_inf[4];
    			if ($catimgnewshome == 1) {
    				if ($catimage == "") { $catimage = "AllTopics.gif"; }
    				if ($catnewshomeimg == "right") { $fl = "left"; }
    				if ($catnewshomeimg == "left") { $fl = "right"; }
    				$size2 = @getimagesize("images/cat/$catimage");
    				$title = "<a href=\"modules.php?name=$module_name&op=viewcat&catid=$catid\" title=\"$cattitle\"><img border=\"0\" src=\"images/cat/$catimage\" width=\"$size2[0]\" style=\"float: $fl\"></a> <a href=\"modules.php?name=$module_name&op=viewst&sid=$sid\">$title</a>";
    			} else {
    				$title = "<a href=\"modules.php?name=$module_name&op=viewcat&catid=$catid\">$cattitle:</a> <a href=\"modules.php?name=$module_name&op=viewst&sid=$sid\">$title</a>";
    			}
		} else {
			if ($catimgnewshome == 1) {
    				$catimage = "AllTopics.gif";
    				if ($catnewshomeimg == "right") { $fl = "left"; }
    				if ($catnewshomeimg == "left") { $fl = "right"; }
    				$size2 = @getimagesize("images/cat/$catimage");
				$title = "<a href=\"modules.php?name=$module_name&op=viewcat&catid=0\"><img border=\"0\" src=\"images/cat/$catimage\" width=\"$size2[0]\" style=\"float: $fl\"></a> <a href=\"modules.php?name=$module_name&op=viewst&sid=$sid\">$title</a>";
			} else {
				$title = "<a href=\"modules.php?name=$module_name&op=viewst&sid=$sid\">$title</a>";
			}
		}
		if ($bodytext != "") {
			$story_link = "<a href=\"modules.php?name=$module_name&op=viewst&sid=$sid\"><img src=\"images/more.gif\" width=\"47\" border=\'0\'  alt=\""._READMORE."\" align=\"right\"></a>";
		} else {
			$story_link = "";
		}
		$com_link = "";
		$tot_hits = "";
		if (defined('IS_ADMMOD')) {
			$tot_hits = " ["._TOTHITS.": $counter | <a href=\"".$adminfold."/".$adminfile.".php?op=EditStory&sid=$sid\">"._EDIT."</a> | <a href=\"".$adminfold."/".$adminfile.".php?op=RemoveStory&sid=$sid\">"._DELETE."</a>]";
		}
		
		if ($images != "" AND file_exists("".$path."/".$images."")) {
			if(file_exists("".$path."/small_".$images."")) {
				$images = "small_".$images."";
			}
			$size2 = @getimagesize("$path/$images");
			$widthimg = $size2[0];
			if ($size2[0] > $sizecatnewshomeimg) { $widthimg = $sizecatnewshomeimg; }
			$xtitle = stripslashes(check_html($row2['title'], "nohtml"));
			$story_pic = "<table border=\"0\" width=\"$widthimg\" cellpadding=\"0\" cellspacing=\"3\" align=\"$catnewshomeimg\">\n<tr>\n<td>\n<a href=\"modules.php?name=$module_name&op=viewst&sid=$sid\"><img border=\"0\" src=\"$path/$images\" width=\"$widthimg\" alt=\"$xtitle\"></a></td>\n</tr>\n</table>\n";		
	} else {
		$story_pic = "";
	}		
	$notes = "";
		themeindex($aid, $time, $title, $hometext, $story_pic, $notes, $story_link, $com_link, $tot_hits,$mau);
		$mau++;
	}
	echo @generate_page($base_url, $all_page, $per_page, $page);
	echo "<br><br>";
	}
    }
    include("footer.php");
}

function bottomblock_tlq($sid, $topicid, $querylang) {
	global $datafold, $module_name, $prefix, $db, $bgcolor3, $hienthi_tlq;
	$sid = intval($sid);
	$topicid = intval($topicid);
	if ($topicid != 0) {
	$xhienthi_tlq = $hienthi_tlq + 1;
	$resulttopic = $db->sql_query("select sid, time, title FROM ".$prefix."_stories where topicid='$topicid' AND sid!='$sid' $querylang ORDER BY sid DESC LIMIT 0,$xhienthi_tlq");
	if ($db->sql_numrows($resulttopic) > 0) {
	echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"5\" width=\"100%\" bgcolor=\"$bgcolor3\">\n"
	. "<tr><td><div style=\"margin-bottom: 3px\"><font class=\"topmore\">"._TINLQ.":</font>\n</div>\n";
	$q = 1;
	while ($rowtopic = $db->sql_fetchrow($resulttopic)) {
	$tsid = intval($rowtopic['sid']);
	$ttitle = stripslashes(check_html($rowtopic['title'], "nohtml"));
	$ttime = formatTimestamp($rowtopic['time'],2);
	if ($q <= $hienthi_tlq) {
		echo "<img border=\"0\" src=\"images/arrow2.gif\" width=\"10\" height=\"5\"><a href=\"modules.php?name=News&op=viewst&sid=$tsid\"><font  class=\"indexhometext\">$ttitle</font></a> [$ttime]<br>\n";
	}
	if ($q == $xhienthi_tlq) {
		echo "<div style=\"margin-top: 3px\" align=\"right\"><a href=\"modules.php?name=News&op=viewtop&topicid=$topicid\"><b><u><font  class=\"indexhometext\">"._READMORE."</font></u></b></a></div>\n";
	}
	$q++;
	}
	echo "</td>\n</tr>\n</table>\n<br><br>\n";
	}
	}
}

function bottomblock_ccd($sid, $catid, $querylang) {
	global $hienthi_ccd, $datafold, $module_name, $prefix, $db;
	$sid = intval($sid);
	$catid = intval($catid);
	if ($catid != 0) {
	$xhienthi_ccd = $hienthi_ccd + 1;
	$resultcat = $db->sql_query("select sid, time, title FROM ".$prefix."_stories where catid='$catid' AND sid!='$sid' $querylang ORDER BY sid DESC LIMIT 0,$xhienthi_ccd");
    	if ($db->sql_numrows($resultcat) > 0) {
		echo "<font class=\"topmore\">"._TINCCD.":</font>\n<br>\n";
		$c = 1;
		while ($rowcat = $db->sql_fetchrow($resultcat)) {
		$csid = intval($rowcat['sid']);
		$ctitle = stripslashes(check_html($rowcat['title'], "nohtml"));
		$ctime = formatTimestamp($rowcat['time'],2);
		if ($c <= $hienthi_ccd) {
			echo "<div style=\"margin-top: 3px; margin-bottom: 3px\"><img border=\"0\" src=\"images/arrow2.gif\" width=\"10\" height=\"5\"><a href=\"modules.php?name=News&op=viewst&sid=$csid\"><font  class=\"indexhometext\">$ctitle</font></a> [$ctime]</div>\n";
        }
        if ($c == $xhienthi_ccd) {
        echo "<div style=\"margin-top: 3px\" align=\"right\"><a href=\"modules.php?name=News&op=viewcat&catid=$catid\"  onMouseOut=\"window.status=''; return true;\" onMouseOver=\"window.status='"._READMORE."'; return true;\"><b><u><font  class=\"indexhometext\">"._READMORE."</font></u></b></a></div>\n";
        }
        $c++;
        }
        echo "<br><hr style=\"border-style: dotted; border-width: 1px\"><br>\n";
    }
}
}

function viewimg($imglink) {
global $datafold, $module_name;
echo"<html>\n<head>\n"
  . "<meta http-equiv=\"Content-Type\" content=\"text/html; charset="._CHARSET."\">\n"
  . "<title>"._VIEWIMG."</title>\n</head>\n<body bgcolor=\"#ECF3FB\" topmargin=\"0\" leftmargin=\"0\" rightmargin=\"0\" bottommargin=\"0\">\n"
  . "<p><a href=\"\" onclick=\"window.close();\"><img border=\"0\" src=\"$imglink\" alt=\""._CLOSEWIN."\"></a></p>\n"
  . "</body>\n</html>";
}

function userbar($sid, $acomm, $comments) {
	global $newsfriend, $newssave, $newsprint, $adminfold, $adminfile, $datafold, $module_name, $articlecomm;
	$sid = intval($sid);
	$test = "";
	if ((defined('IS_ADMMOD')) || ($newsprint==1) || ($newsprint==2 AND (defined('IS_USER')))) {
	$test .= "&nbsp;<a href=\"#\" onClick=\"MM_openBrWindow('modules.php?name=$module_name&file=print&sid=$sid','','scrollbars=yes,width=640,height=500')\" onMouseOut=\"window.status=''; return true;\" onMouseOver=\"window.status='"._PRINTER."'; return true;\"><img src=\"images/print.gif\" border=\"0\" alt=\""._PRINTER."\" title=\""._PRINTER."\" width=\"16\" height=\"16\"></a>\n";
}
if ((defined('IS_ADMMOD')) || ($newssave==1) || ($newssave==2 AND (defined('IS_USER')))) {
	$test .= "&nbsp;<a href=\"modules.php?name=$module_name&file=save&sid=$sid\" onMouseOut=\"window.status=''; return true;\" onMouseOver=\"window.status='"._SAVE."'; return true;\"><img src=\"images/save.gif\" border=\"0\" alt=\""._SAVE."\" title=\""._SAVE."\" width=\"16\" height=\"16\"></a>\n";
}
if ((defined('IS_ADMMOD')) || ($newsfriend==1) || ($newsfriend==2 AND (defined('IS_USER')))) {
	$test .= "&nbsp;<a href=\"#\" onClick=\"MM_openBrWindow('modules.php?name=$module_name&file=friend&op=FriendSend&sid=$sid','','scrollbars=no,width=400,height=370')\" onMouseOut=\"window.status=''; return true;\" onMouseOver=\"window.status='"._FRIEND."'; return true;\"><img src=\"images/friend.gif\" border=\"0\" alt=\""._FRIEND."\" title=\""._FRIEND."\" width=\"16\" height=\"16\"></a>\n";
}
if ((defined('IS_ADMMOD')) || ($articlecomm == 1 AND $acomm == 0) || ($articlecomm == 2 AND $acomm == 0 AND (defined('IS_USER')))) {
	$test .= "&nbsp;<a href=\"#\" onClick=\"MM_openBrWindow('modules.php?name=$module_name&file=comm&sid=$sid','','scrollbars=no,width=500,height=500')\" onMouseOut=\"window.status=''; return true;\" onMouseOver=\"window.status='"._COMMENTSQ."'; return true;\"><img src=\"images/comm.gif\" border=\"0\" alt=\""._COMMENTSQ."\" title=\""._COMMENTSQ."\" width=\"16\" height=\"16\"></a>\n";
}
if ($test != "") {
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n<tr>\n<td>\n$test\n</td>\n";
if (defined('IS_ADMMOD')) {
    echo "<td align=\"right\">[ <a href=\"".$adminfold."/".$adminfile.".php?op=adminnews\">"._ADD."</a> | <a href=\"".$adminfold."/".$adminfile.".php?op=EditStory&sid=$sid\">"._EDIT."</a> | <a href=\"".$adminfold."/".$adminfile.".php?op=RemoveStory&sid=$sid\">"._DELETE."</a> ]</td>\n";
}
if (($comments!=0) AND ((defined('IS_ADMMOD')) || ($articlecomm == 1 AND $acomm == 0) || ($articlecomm == 2 AND $acomm == 0 AND (defined('IS_USER'))))) {
echo "<td align=\"right\"><b><a href=\"modules.php?name=$module_name&op=showcomm&sid=$sid\">"._READREST."</a></b> ("._ALL.": $comments)</td>";
}
echo "</tr></table>\n";
echo "<hr style=\"border-style: dotted; border-width: 1px\"><br>\n";
}
}

function combl_bar($catid) {
global $nvcat, $nvcat2, $hourdiff, $addnews, $datafold, $prefix, $db, $module_name, $user, $anonpost, $bgcolor2;

echo"<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\" width=\"100%\" align=\"center\" bgcolor=\"$bgcolor2\">\n<tr>\n";
if ((defined('IS_ADMMOD')) || ($addnews==1) || (($addnews==2) AND (defined('IS_USER')))) {
$size3 = getimagesize("images/modules/$module_name/submitnews.gif");
echo "<td width=\"75\">\n<a href=\"#\" onClick=\"MM_openBrWindow('modules.php?name=News&file=addnews','','scrollbars=no,width=590,height=750')\" onMouseOut=\"window.status=''; return true;\" onMouseOver=\"window.status='"._SUBMITNEWS."'; return true;\">\n"
  . "<img border=\"0\" src=\"images/modules/$module_name/submitnews.gif\" width=\"$size3[0]\" height=\"$size3[1]\" title=\""._SUBMITNEWS."\" alt=\""._SUBMITNEWS."\"></a></td>\n";
}
echo "<td align=\"right\">\n"
  . "<form method=\"POST\" action=\"modules.php?name=$module_name\">\n"
  . "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n<td><select name=\"day\">\n";
	for($i=1;$i <= 31;$i++) {
		echo "<option value=\"".str_pad($i, 2, "0", STR_PAD_LEFT)."\"";
		if($i == date("d",time()+$hourdiff * 60)) { echo " selected"; }
		echo ">".str_pad($i, 2, "0", STR_PAD_LEFT)."</option>\n";
	}

echo"</select></td>\n<td><select name=\"month\">\n";
for($i=1;$i <= 12;$i++) {
		echo "<option value=\"".str_pad($i, 2, "0", STR_PAD_LEFT)."\"";
		if($i == date("m",time()+$hourdiff * 60)) { echo " selected"; }
		echo ">".str_pad($i, 2, "0", STR_PAD_LEFT)."</option>\n";
	}
echo"</select></td>\n<td><select name=\"year\">\n";
	$z = date("Y",time()+$hourdiff * 60);
	for($i=$z;$i >= ($z - 4);$i--) {
		echo "<option value=\"$i\"";
		if($i == $z) { echo " selected"; }
		echo ">$i</option>\n";
	}
echo"</select></td>\n"
  . "<input type=\"hidden\" name=\"pozit\" value=\"1\">\n"
  . "<input type=\"hidden\" name=\"catid\" value=\"$catid\">\n"
  . "<input type=\"hidden\" name=\"op\" value=\"archive\">\n";
	$size3 = @getimagesize("images/modules/$module_name/archive.gif");
echo"<td width=\"$size3[0]\"><input type=\"image\" src=\"images/modules/$module_name/archive.gif\" alt=\""._SEARCH."\" value=\""._SEARCH."\" style=\"border: 0\"></td>\n"
  . "</tr>\n</table>\n</form>\n</td>\n"
  ."</tr>\n</table>\n";
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"margin-top: 4\" align=\"center\">\n<tr>\n";
if(isset($nvcat)) { $numcatc = sizeof($nvcat); } else { $numcatc=0; }
    if ($numcatc > 0) {
    echo"<script language=\"JavaScript\">\n"
    . "<!-- Hide the script from old browsers --\n"
    . "function JumpToo(form) { \n"
    . "var myindex=form.catid.selectedIndex;\n"
    . "if (form.catid.options[myindex].value != \"0\") {\n"
    . "parent.location=form.catid.options[myindex].value; \n"
    . "}\n"
    . "}\n"
    . "//--> \n"
    . "</script>\n";
    echo"<td>\n<form method=\"post\">\n"
    . "<select name=\"catid\" onChange=\"JumpToo(this.form)\"><option value=\"0\">"._EXPRESSCAT."</option>\n";
    for ($b=0;$b < sizeof($nvcat);$b++) {
    $ecat_inf = explode("|",$nvcat[$b]);
    if($ecat_inf[1]=='0') {
    $ecatid = intval($ecat_inf[0]);
    $etitle = stripslashes(check_html($ecat_inf[2], "nohtml"));
    echo "<option value=\"modules.php?name=$module_name&op=viewcat&catid=$ecatid\">$etitle</option>\n";
    if($ecat_inf[8]!="") {
    $esubcat_inf = explode(",",$ecat_inf[8]);
    for ($k=0;$k < sizeof($esubcat_inf);$k++) {
    if($esubcat_inf[$k]!="") {
    $esubcat_inf2 = explode("|", $nvcat2[intval($esubcat_inf[$k])]);
    $ecatid2 = intval($esubcat_inf2[0]);
    $etitle2 = stripslashes(check_html($esubcat_inf2[2], "nohtml"));
    $etitle2 = "$etitle &raquo; $etitle2";
    echo "<option value=\"modules.php?name=$module_name&op=viewcat&catid=$ecatid2\">$etitle2</option>\n";
    }
    }
    }
    }
    }
    echo "</select></form></td>\n";
    }
$size3 = @getimagesize("images/modules/$module_name/up.gif");
echo "<td align=\"center\" width=\"100%\" valign=\"bottom\">\n"
  . "<a href=\"#top\" onMouseOut=\"window.status=''; return true;\" onMouseOver=\"window.status='"._TOPPAGE."'; return true;\"><img border=\"0\" src=\"images/modules/$module_name/up.gif\" width=\"$size3[0]\" height=\"$size3[1]\" alt=\""._TOPPAGE."\"></a></td>\n";
    echo "<form action=\"modules.php?name=Search\" method=\"post\">"
    . "<td align=\"right\">"
    . "<input type=\"text\" name=\"query\" size=\"23\" maxLength=\"57\" onblur=\"if (this.value==''){this.value='"._SEARCH."';}\" onfocus=\"if (this.value=='"._SEARCH."') {this.value = '';}\" value=\""._SEARCH."\" style=\"text-align: center\">"
  . "</td>"
  . "<td width=\"19\">";
echo"<input type=\"image\" src=\"images/modules/$module_name/go.gif\" alt=\""._SEARCH."\" value=\""._SEARCH."\" style=\"border: 0\">"
  . "</td>"
  . "</form>";
  echo "</tr>\n</table>\n";
}

function showcomm($sid) {
	global $newspagenum, $articlecomm, $adminfold, $adminfile, $datafold, $prefix, $user_prefix, $db, $module_name, $page_title, $pagenum, $index, $bgcolor2, $bgcolor3;
      $sid = intval($sid);
	$result = $db->sql_query("SELECT title, acomm, topicid, catid FROM ".$prefix."_stories WHERE sid='$sid'");
	$row = $db->sql_fetchrow($result);
	$title = stripslashes(check_html($row['title'], "nohtml"));
	$acomm = intval($row['acomm']);
	$topicid = intval($row['topicid']);
	$catid = intval($row['catid']);
      if ((!defined('IS_ADMMOD')) AND (($db->sql_numrows($result) != 1) OR ($articlecomm == 0) OR ($acomm == 1))) { Header("Location: index.php"); exit; }
	$page_title = ""._COMMENTSAR." | $title";
	$numf = $db->sql_fetchrow($db->sql_query("SELECT COUNT(*) FROM ".$prefix."_stories_comments WHERE sid='$sid'"));
	$page = ( isset($_GET['page']) ) ? intval($_GET['page']) : 0;
	$all_page = ( $numf[0] ) ? $numf[0] : 1;
	$per_page = intval($newspagenum);
	$base_url = "modules.php?name=$module_name&op=showcomm&sid=$sid";
	$result = $db->sql_query("SELECT * FROM ".$prefix."_stories_comments WHERE sid='$sid' ORDER BY date desc LIMIT $page,$per_page");
	include("header.php");
	echo"<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n<tr>\n<td valign=\"top\">"
	. "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\" width=\"100%\">\n"
	. "<tr>\n<td align=\"center\">\n<a name=\"top\"></a>\n<h2>$title\n"
	. "</td>\n</tr><tr>\n<td align=\"center\"><a href=\"modules.php?name=$module_name&op=viewst&sid=$sid\" onMouseOut=\"window.status=''; return true;\" onMouseOver=\"window.status='"._ARTICLECONTENT."'; return true;\">"
	. ""._ARTICLECONTENT."\n<a> | <a href=\"#\" onClick=\"MM_openBrWindow('modules.php?name=$module_name&file=comm&sid=$sid','','scrollbars=no,width=500,height=500')\" onMouseOut=\"window.status=''; return true;\" onMouseOver=\"window.status='"._COMMENTSQ."'; return true;\">"._COMMENTSQ."</a>\n</td>\n</tr>\n</table>\n"
	. "<hr style=\"border-style: dotted; border-width: 1px\">";
	echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n";
        $a = 0;
	while ($row = $db->sql_fetchrow($result)) {
	$tid = intval($row['tid']);
	$send_date = formatTimestamp($row['date'],2);
	$sender_name = $row['name'];
	$sender_email = "Email: <a href=\"mailto:$row[email]\">$row[email]</a>";
	$result2 = $db->sql_query("SELECT user_id, user_viewemail FROM ".$user_prefix."_users WHERE username='$sender_name'");
	$row2 = $db->sql_fetchrow($result2);
	$viewmail = $row2['user_viewemail'];
        if ($db->sql_numrows($result2) == 1) {
        $sender_name = "<a href=\"modules.php?name=Your_Account&op=userinfo&user_id=".$row2['user_id']."\">$sender_name</a>";
        if ((!defined('IS_ADMMOD')) && ($viewmail == 0)) {
        $sender_email = "";
        }
        }
        $sender_host = $row['host_name'];
        $com_text = $row['comment'];
        $ip = "<a title=\""._TOP_PAGE."\" href=\"#top\" onMouseOut=\"window.status=''; return true;\" onMouseOver=\"window.status='"._TOP_PAGE."'; return true;\"><font face=\"Arial\" color=\"#DC0312\" size=\"2\"><span style=\"text-decoration: none\">&#9650;</span></font></a>\n";
        $delcomm = "<a href=\"#\" onClick=\"MM_openBrWindow('modules.php?name=$module_name&file=comm&sid=$sid','','scrollbars=no,width=500,height=500')\" onMouseOut=\"window.status=''; return true;\" onMouseOver=\"window.status='"._COMMENTSQ."'; return true;\"><img border=\"0\" src=\"images/modules/$module_name/comm_element.gif\" width=\"24\" height=\"24\" hspace=\"3\" vspace=\"3\" alt=\""._COMMENTSQ."\" title=\""._COMMENTSQ."\"></a>";
        if (defined('IS_ADMMOD')) {
        $ip = "IP: <a href=\"".$adminfold."/".$adminfile.".php?op=ConfigureBan&bad_ip=$sender_host\">$sender_host</a>\n";
        $delcomm = "<a href=\"".$adminfold."/".$adminfile.".php?op=EditStoriesComment&tid=$tid\" title=\""._EDIT."\"><img border=\"0\" src=\"images/modules/$module_name/comm_element.gif\" width=\"24\" height=\"24\" hspace=\"3\" vspace=\"3\"></a>";
        }
        $bgcolor = $bgcolor2;
        if ($a%2 == 1) {
        $bgcolor = $bgcolor3;
        }
echo"<tr>\n<td>\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n"
  . "<tr>\n<td style=\"border-left:2px solid #DC0312\">\n"
  . "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n"
  . "<tr>\n<td width=\"30\" style=\"border-top:2px solid #DC0312\">$delcomm</td>\n<td>\n"
  . "<li type=\"circle\">"._SENDCOMM.": $sender_name, $sender_email</li>\n"
  . "<li type=\"circle\">"._COMMDATE.": $send_date</li>\n</td>\n"
  . "<td align=\"right\">$ip</td>\n</tr>\n</table>\n</td>\n</tr>\n<tr>\n"
  . "<td style=\"border-left:2px solid #DC0312; border-bottom:2px solid #FFDB29; background-color: $bgcolor\">\n"
  . "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\" width=\"100%\">\n"
  . "<tr>\n<td class=\"indexhometext\">$com_text</td>\n</tr>\n</table>\n"
  . "</td>\n</tr>\n<tr>\n<td>&nbsp;</td>\n</tr>\n</table>\n</td>\n</tr>\n";
        $a++;
        }
        echo "</table>";
        echo @generate_page($base_url, $all_page, $per_page, $page);
	echo "<br><br>";
       echo "</td>\n";
       echo "</tr>\n</table>";
       include("footer.php");
}

function viewst() {
	global $comblbarstat, $hienthi_ccd, $acomm, $hienthi_tlq, $sizenewsarticleimg, $newsarticleimg, $path, $page_title, $page_title2, $key_words, $header_page_keyword, $datafold, $currentlang, $multilingual, $prefix, $user_prefix, $db, $anonymous, $articlecomm, $module_name, $index, $bgcolor2, $ThemeSel;
	$sid = ( isset($_GET['sid']) ) ? intval($_GET['sid']) : intval($_POST['sid']);
	if(!$sid || $sid==0) { Header("Location: index.php"); exit(); }
	$result = $db->sql_query("select * FROM ".$prefix."_stories where sid='$sid' AND (alanguage='$currentlang' OR alanguage='')");
	if ($numrows = $db->sql_numrows($result) != 1) { Header("Location: index.php"); die(); }
	$row = $db->sql_fetchrow($result);
	$catid = intval($row['catid']);
	$aid = stripslashes($row['aid']);
	$time = formatTimestamp($row['time'],2);
	$title = stripslashes(check_html($row['title'], "nohtml"));
	$hometext = stripslashes($row['hometext']);
	$bodytext = stripslashes($row['bodytext']);
	$images = $row['images'];
	$imgtext = stripslashes(check_html($row['imgtext'], "nohtml"));
	$notes = stripslashes($row['notes']);
	$acomm = intval($row['acomm']);
	$comments = stripslashes($row['comments']);
	$topicid = intval($row['topicid']);
	$source = stripslashes(check_html($row['source'], "nohtml"));

	$db->sql_query("UPDATE ".$prefix."_stories SET counter=counter+1 where sid=$sid");
	$header_page_keyword = "$title $hometext $bodytext $notes";
	$key_words = $title;
	list($cattitle, $catparentid) = $db->sql_fetchrow($db->sql_query("select title, parentid from ".$prefix."_stories_cat where catid='$catid'"));
	$page_title2 = "<a href=\"modules.php?name=$module_name&op=viewcat&catid=$catid\">$cattitle</a>";
	$page_title = "$cattitle | $title";
	if($catparentid!=0) {
		list($cattitle2) = $db->sql_fetchrow($db->sql_query("select title from ".$prefix."_stories_cat where catid='$catparentid'"));
	$page_title2 = "<a href=\"modules.php?name=$module_name&op=viewcat&catid=$catparentid\">$cattitle2</a> &raquo; <a href=\"modules.php?name=$module_name&op=viewcat&catid=$catid\">$cattitle</a>";
	$page_title = "$cattitle2 | $cattitle | $title";
	}
	include("header.php");
	if ($source != "") { $source = "("._ISTOK." <i>$source</i>)"; }
	if ($images != "") {
        $ximages = "$path/$images";
        $size2 = @getimagesize("$ximages");
        if (file_exists("".$path."/small_".$images."")) {
        		$images = "small_".$images."";
		}
        if ($size2[0] > $sizenewsarticleimg) {
        $story_pic = "<table border=\"0\" width=\"$sizenewsarticleimg\" cellpadding=\"0\" cellspacing=\"3\" align=\"$newsarticleimg\">\n<tr>\n<td>\n
        <img style=\"cursor: hand\" onclick=\"return MM_openBrWindow('viewimg.php?imglink=$ximages','viewclick','scrollbars=no,width=$size2[0],height=$size2[1],resizable=no');\" border=\"0\" src=\"$path/$images\" width=\"$sizenewsarticleimg\" alt=\""._VIEWIMG."\">
        </td>\n</tr>\n<tr>\n<td align=\"center\">$imgtext</td>\n</tr>\n</table>\n";
        } else {
        $story_pic = "<table border=\"0\" width=\"$size2[0]\" cellpadding=\"0\" cellspacing=\"3\" align=\"$newsarticleimg\">\n<tr>\n<td>\n
        <img border=\"0\" src=\"$path/$images\" width=\"$size2[0]\" alt=\"$imgtext\"></td>\n</tr>\n<tr>\n<td align=\"center\">$imgtext</td>\n</tr>\n</table>\n";
        }
	} else {
        $story_pic = "";
	}

	echo"<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n<tr>\n<td valign=\"top\" width=\"100%\">";
	themearticle($aid, $time, $title, $hometext, $bodytext, $notes, $story_pic, $source);
	if ($multilingual == 1) { $querylang = "AND (alanguage='$currentlang' OR alanguage='')"; } else { $querylang = ""; }
	if ($hienthi_tlq > 0) { bottomblock_tlq($sid, $topicid, $querylang); }
	userbar($sid, $acomm, $comments);
	if ($hienthi_ccd > 0) { bottomblock_ccd($sid, $catid, $querylang); }
	if ($comblbarstat) { combl_bar($catid); }
	echo "</td>\n";		
echo "</tr>\n</table>";
include ("footer.php");
}

function viewcat($catid) {
	global $nvcat, $nvcat2, $sizeimgskqa, $page_title, $page_title2, $key_words, $header_page_keyword, $catimgnewshome, $catnewshomeimg, $module_name, $sizecatnewshomeimg, $path, $newspagenum, $adminfold, $adminfile, $db, $prefix, $multilingual, $currentlang, $pagenum, $admin;
	$catid = intval($catid);
	if(!isset($nvcat2[$catid]) || $nvcat2[$catid]=="") { Header("Location: modules.php?name=$module_name"); exit; }
	$cat_inf = explode("|",$nvcat2[$catid]);
	$catparentid = intval($cat_inf[1]);
	$cattitle = stripslashes(check_html($cat_inf[2], "nohtml"));
	$storieshome2 = intval($cat_inf[6]);
	$page_title = $key_words = $header_page_keyword = $cattitle;
	$page_title2 = "<a href=\"modules.php?name=$module_name&op=viewcat&catid=$catid\">".$cattitle."</a>";
	if($catparentid!=0) {
		$cat_inf2 = explode("|",$nvcat2[$catparentid]);
		$mcattitle = stripslashes(check_html($cat_inf2[2], "nohtml"));
		$page_title = "$mcattitle | $cattitle";
		$page_title2 = "<a href=\"modules.php?name=$module_name&op=viewcat&catid=$catparentid\">".$mcattitle."</a> &raquo; <a href=\"modules.php?name=$module_name&op=viewcat&catid=$catid\">".$cattitle."</a>";
		$key_words = $header_page_keyword = "$mcattitle, $cattitle";
	}
	include("header.php");
	$whe = "WHERE (catid='$catid'";
	$subcat = explode(",",$cat_inf[8]);
	$numsubcat = sizeof($subcat);
	if($cat_inf[8]=="") $numsubcat=0;
	for ($i=0;$i < sizeof($subcat);$i++) {
		if($subcat[$i]!="") { $whe .= "OR catid='".intval($subcat[$i])."'"; }
	}
	$whe .= ")";
	if ($storieshome2 != 0) {
		$xstorieshome = $storieshome2;
	} else {
		$liststhm = array();
		$m=0;
		for($n=0;$n < sizeof($subcat);$n++) {
			$nvcat2_ar2 = explode("|",$nvcat2[$subcat[$n]]);
			if($nvcat2_ar2[6]!=0) { $liststhm[$m] = intval($nvcat2_ar2[6]); $m++; }
		}
		rsort($liststhm);
		$xstorieshome = intval($liststhm[0]);
	}
	if ($multilingual == 1) { $querylang = "AND (alanguage='$currentlang' OR alanguage='')"; } else { $querylang = ""; }
	$numx = $db->sql_fetchrow($db->sql_query("SELECT COUNT(*) FROM ".$prefix."_stories WHERE sid='$xstorieshome' $querylang"));
	if($numx[0]==1) {
		$result2 = $db->sql_query("SELECT * FROM ".$prefix."_stories WHERE sid='$xstorieshome'");
	} else {
		$result2 = $db->sql_query("SELECT * FROM ".$prefix."_stories $whe $querylang ORDER BY sid DESC LIMIT 0,1");
	}
	if ($db->sql_numrows($result2) != 0) {
		$row2 = $db->sql_fetchrow($result2);
		$sid_st = intval($row2['sid']);
    		$title_st = "<a href=\"modules.php?name=News&amp;op=viewst&amp;sid=$sid_st\">".stripslashes(check_html($row2['title'], "nohtml"))."</a>";
		$hometext_st = stripslashes($row2['hometext']);
		$image_st = $row2['images'];
		if (file_exists("".INCLUDE_PATH."".$path."/nst_".$image_st."")) {
			$image_st = "nst_".$image_st."";
		} elseif(file_exists("".INCLUDE_PATH."".$path."/small_".$image_st."")) {
			$image_st = "small_".$image_st."";
		}
		$size2 = @getimagesize("$path/$image_st");
		$widthimg = $size2[0];
		if($widthimg > $sizeimgskqa) $widthimg = $sizeimgskqa;
		if ($image_st != "") { $image_st01 = "<table border=\"0\" width=\"$widthimg\" cellpadding=\"0\" cellspacing=\"3\" align=\"$catnewshomeimg\">\n<tr>\n<td>\n<a href=\"modules.php?name=News&amp;op=viewst&amp;sid=$sid_st\" title=\"".stripslashes(check_html($row2['title'], "nohtml"))."\"><img border=\"0\" src=\"$path/$image_st\" width=\"$widthimg\"></a></td>\n</tr>\n</table>\n";	} else { $image_st01 = ""; }
		$story_link = "<a href=\"modules.php?name=News&amp;op=viewst&amp;sid=$sid_st\"><img src='images/more.gif' border='0'  alt=\""._READMORE."\" align=\"right\"></a>";
		$numf = $db->sql_fetchrow($db->sql_query("SELECT COUNT(*) FROM ".$prefix."_stories WHERE catid='$catid' AND sid!='$sid_st' $querylang"));
		$page = ( isset($_GET['page']) ) ? intval($_GET['page']) : 0;
		$all_page = ( $numf[0] ) ? $numf[0] : 1;
		$per_page = intval($newspagenum);
		$base_url = "modules.php?name=$module_name&op=viewcat&catid=$catid";
		if($page==0) themenewsst($title_st, $image_st01,$hometext_st, $story_link);
		
		echo"<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n<tr>\n<td valign=\"top\">";
		$a=0;
		if($numsubcat > 0 AND $numf[0] > 0 && $page==0) {
   			Opentable();
   			echo "<table border=\"0\" cellpadding=\"2\" style=\"border-collapse: collapse\" width=\"100%\">\n";
 		}
		$result = $db->sql_query("SELECT * FROM ".$prefix."_stories WHERE catid='$catid' AND sid!='$sid_st' $querylang ORDER BY sid DESC LIMIT $page,$per_page");
		while ($row = $db->sql_fetchrow($result)) {
			$sid = intval($row['sid']);
			$aid = stripslashes($row['aid']);
			$time = formatTimestamp($row['time'],2);
			$title = stripslashes(check_html($row['title'], "nohtml"));
			$hometext = stripslashes($row['hometext']);
			$bodytext = stripslashes($row['bodytext']);
			$images = $row['images'];
			$imgtext = stripslashes(check_html($row['imgtext'], "nohtml"));
			$notes = stripslashes($row['notes']);
			$acomm = intval($row['acomm']);
			$counter = intval($row['counter']);
			$comments = stripslashes($row['comments']);
			$source = stripslashes(check_html($row['source'], "nohtml"));
			$title = "<a href=\"modules.php?name=News&op=viewst&sid=$sid\">$title</a>";
			$story_link = "";
			if ($bodytext != "") {
				$story_link = "<a href=\"modules.php?name=News&op=viewst&sid=$sid\"><img src='images/more.gif' border='0'  alt=\""._READMORE."\" align=\"right\"></a>";
			}
			$com_link = "";
			if (defined('IS_ADMMOD')) {
				$com_link .= " ("._COMMENTSQ.": $comments  | ";
				$tot_hits = ""._TOTHITS.": $counter | <a href=\"".$adminfold."/".$adminfile.".php?op=EditStory&sid=$sid\">"._EDIT."</a> | <a href=\"".$adminfold."/".$adminfile.".php?op=RemoveStory&sid=$sid\">"._DELETE."</a>)";
			}
			$story_pic = "";
			if ($images != "" AND file_exists("".$path."/".$images."")) {
				if(file_exists("".$path."/small_".$images."")) { $images = "small_".$images.""; }
				$size2 = @getimagesize("$path/$images");
				$widthimg = $size2[0];
				if ($size2[0] > $sizecatnewshomeimg) { $widthimg = $sizecatnewshomeimg; }
				$story_pic = "<table border=\"0\" width=\"$widthimg\" cellpadding=\"0\" cellspacing=\"3\" align=\"$catnewshomeimg\">\n<tr>\n<td>\n<a href=\"modules.php?name=$module_name&op=viewst&sid=$sid\"><img border=\"0\" src=\"$path/$images\" width=\"$widthimg\"></a></td>\n</tr>\n</table>\n";		
			}
			$notes = "";
			if($numsubcat > 0 AND $numf[0] > 0 && $page==0) {
				echo "<tr>\n";
				echo "<td width=\"7\">\n";
				echo "<img border=\"0\" src=\"images/dot.gif\" width=\"7\" height=\"10\"></td>\n";
				echo "<td><b>$title</b></td>\n";
				echo "<td width=\"120\" align=\"right\" class=grey>$time</td>\n";
				echo "</tr>\n";
			}
			if($numf[0] > 0 AND (($numsubcat > 0 AND $page!=0) || $numsubcat==0)) {
				themeindex($aid, $time, $title, $hometext, $story_pic, $notes, $story_link, $com_link, $tot_hits, $a);
				$a++;
			}
		}
		if($numsubcat > 0 AND $numf[0] > 0 && $page==0) {
			echo "</table>\n";
			CloseTable();
		}
		echo "<p align=\"right\">".@generate_page($base_url, $all_page, $per_page, $page)."</p>";
		if($numsubcat > 0 && $page==0) {
			$mau=0;
			for ($v=0;$v < sizeof($subcat);$v++) {
				if($nvcat2[$subcat[$v]]!="") {
					$subcat_inf = explode("|",$nvcat2[$subcat[$v]]);
					$cat_id = intval($subcat_inf[0]);
					$cat_title = stripslashes(check_html($subcat_inf[2], "nohtml"));
					$linkshome = intval($subcat_inf[7]);
					$storieshome = intval($subcat_inf[6]);
					$catimage = $subcat_inf[4];
					if ($storieshome != 0 AND $storieshome!=$sid_st) {
						$result3 = $db->sql_query("SELECT * FROM ".$prefix."_stories WHERE sid='$storieshome'");
					} else {
						$result3 = $db->sql_query("SELECT * FROM ".$prefix."_stories WHERE catid='$cat_id' AND sid!='$sid_st' $querylang ORDER BY sid DESC LIMIT 0,1");
					}
					if ($db->sql_numrows($result3) != 0) {
						$cat_name = "<a href=\"modules.php?name=$module_name&op=viewcat&catid=$cat_id\" class=\"storytitle\">$cat_title</a>";
						categoryname($cat_name);
						$row3 = $db->sql_fetchrow($result3);
						$sid3 = intval($row3['sid']);
						$aid3 = stripslashes($row3['aid']);
						$title3 = stripslashes(check_html($row3['title'], "nohtml"));
						$time3 = formatTimestamp($row3['time'],2);
						$hometext3 = stripslashes($row3['hometext']);
						$bodytext3 = stripslashes($row3['bodytext']);
						$images3 = $row3['images'];
						$comments3 = stripslashes($row3['comments']);
						$counter3 = intval($row3['counter']);
						$notes3 = stripslashes($row3['notes']);
						$acomm3 = intval($row3['acomm']);
						$imgtext3 = stripslashes(check_html($row3['imgtext'], "nohtml"));
						$source3 = stripslashes(check_html($row3['source'], "nohtml"));
						$topicid3 = intval($row3['topicid']);		
						if ($catimgnewshome == 1) {
    							if ($catimage == "") { $catimage = "AllTopics.gif"; }
    							if ($catnewshomeimg == "right") { $fl = "left"; }
    							if ($catnewshomeimg == "left") { $fl = "right"; }
							$size2 = @getimagesize("images/cat/$catimage");
    							$title3 = "<a href=\"modules.php?name=$module_name&op=viewcat&catid=$cat_id\" title=\"$cat_title\"><img border=\"0\" src=\"images/cat/$catimage\" width=\"$size2[0]\" style=\"float: $fl\"></a> <a href=\"modules.php?name=$module_name&op=viewst&sid=$sid3\">$title3</a>";
    						} else {
    							$title3 = "<a href=\"modules.php?name=$module_name&op=viewst&sid=$sid3\">$title3</a>\n";
						}
						$story_link3 = "";
						if ($bodytext3 != "") {
							$story_link3 = "<a href=\"modules.php?name=$module_name&op=viewst&sid=$sid3\"><img src='images/more.gif' border='0' width=\"47\" height=\"9\" alt=\""._READMORE."\" align=\"right\"></a>";
						}
						$com_link3 = "";
						if (defined('IS_ADMMOD')) {
	    						$com_link3 .= " ("._COMMENTSQ.": $comments3  | ";
							$tot_hits3 = ""._TOTHITS.": $counter3 | <a href=\"".$adminfold."/".$adminfile.".php?op=EditStory&sid=$sid3\">"._EDIT."</a> | <a href=\"".$adminfold."/".$adminfile.".php?op=RemoveStory&sid=$sid3\">"._DELETE."</a>)";
						}
						$story_pic3 = "";
						if ($images3 != "" AND file_exists("".$path."/".$images3."")) {
							if(file_exists("".$path."/small_".$images3."")) {
								$images3 = "small_".$images3."";
							}
							$size2 = @getimagesize("$path/$images3");
							$widthimg = $size2[0];
							if ($size2[0] > $sizecatnewshomeimg) { $widthimg = $sizecatnewshomeimg; }
							$story_pic3 = "<table border=\"0\" width=\"$widthimg\" cellpadding=\"0\" cellspacing=\"3\" align=\"$catnewshomeimg\">\n<tr>\n<td>\n<a href=\"modules.php?name=$module_name&op=viewst&sid=$sid3\"><img border=\"0\" src=\"$path/$images3\" width=\"$widthimg\"></a></td>\n</tr>\n</table>\n";		
						}
						$notes3 = "";
						$result4 = $db->sql_query("SELECT sid, time, title FROM ".$prefix."_stories WHERE catid='$cat_id' AND sid!='$sid3' $querylang ORDER BY sid DESC LIMIT $linkshome3");
						if ($db->sql_numrows($result4) != 0) {
							$notes3 .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td style=\"text-align: justify\" valign=\"top\">\n";
							$notes3 .= "<p class=topmore style=\"margin-top: 5px; margin-bottom: 5px\">"._MORENEWS2."</p>";
	    						while ($row4 = $db->sql_fetchrow($result4)) {
	    							$sid4 = intval($row4['sid']);
								$title4 = stripslashes(check_html($row4['title'], "nohtml"));
								$time4 = formatTimestamp($row4['time'],2);
								$notes3 .= "<img src='images/modules/$module_name/arrow3.gif' border='0' width=\"10\"><a href='modules.php?name=$module_name&op=viewst&sid=$sid4' class=indexlink>$title4</a>  <font class=grey>[$time4]</font><br>";
	    						}
							$notes3 .= "</td></tr></table>";
						}
						themeindex($aid3, $time3, $title3, $hometext3, $story_pic3, $notes3, $story_link3, $com_link3, $tot_hits3,$mau);
						$mau++;
    					}
    				}
    			}
    		}
		echo "</td>\n</tr>\n</table>";
	}
	include("footer.php");
}

function viewtop($topicid) {
	global $catnewshomeimg, $module_name, $sizecatnewshomeimg, $path, $newspagenum, $adminfold, $adminfile, $db, $prefix, $time, $multilingual, $currentlang, $pagenum, $admin;
	$topicid = intval($topicid);
    if ($topicid == 0) { Header("Location: modules.php?name=$module_name"); exit; }
    if ($multilingual == 1) { $querylang = "AND (alanguage='$currentlang' OR alanguage='')"; } else { $querylang = ""; }
    $numf = $db->sql_fetchrow($db->sql_query("SELECT COUNT(*) FROM ".$prefix."_stories WHERE topicid='$topicid' $querylang"));
	$page = ( isset($_GET['page']) ) ? intval($_GET['page']) : 0;
	$all_page = ( $numf[0] ) ? $numf[0] : 1;
	$per_page = intval($newspagenum);
	$base_url = "modules.php?name=$module_name&op=viewtop&topicid=$topicid";
    $result = $db->sql_query("SELECT * FROM ".$prefix."_stories WHERE topicid='$topicid' $querylang ORDER BY sid DESC LIMIT $page,$per_page");
    include("header.php");
    echo"<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n<tr>\n<td valign=\"top\">";
	list($topictitle) = $db->sql_fetchrow($db->sql_query("select title from ".$prefix."_stories_topic where topicid='$topicid'"));
    echo"<center><b>".stripslashes(check_html($row2['topictitle'], "nohtml"))."</b></center><br>";
   $a=0;
   while ($row = $db->sql_fetchrow($result)) {
        $sid = intval($row['sid']);
        $aid = stripslashes($row['aid']);
        $time = formatTimestamp($row['time'],2);
        $title = stripslashes(check_html($row['title'], "nohtml"));
        $hometext = stripslashes($row['hometext']);
        $bodytext = stripslashes($row['bodytext']);
        $images = $row['images'];
        $imgtext = stripslashes(check_html($row['imgtext'], "nohtml"));
        $notes = stripslashes($row['notes']);
        $acomm = intval($row['acomm']);
        $counter = intval($row['counter']);
        $comments = stripslashes($row['comments']);
        $source = stripslashes(check_html($row['source'], "nohtml"));
        $title = "<a href=\"modules.php?name=News&op=viewst&sid=$sid\">$title</a>";
        $story_link = "";
        if ($bodytext != "") {
        $story_link = "<a href=\"modules.php?name=News&op=viewst&sid=$sid\"><img src='images/more.gif' border='0'  alt=\""._READMORE."\" align=\"right\"></a>";
        }
        $com_link = "";
        if (defined('IS_ADMMOD')) {
        $com_link .= " ("._COMMENTSQ.": $comments  | ";
        $tot_hits = ""._TOTHITS.": $counter | <a href=\"".$adminfold."/".$adminfile.".php?op=EditStory&sid=$sid\">"._EDIT."</a> | <a href=\"".$adminfold."/".$adminfile.".php?op=RemoveStory&sid=$sid\">"._DELETE."</a>)";
        }
        $story_pic = "";
		if ($images != "" AND file_exists("".$path."/".$images."")) {
			if(file_exists("".$path."/small_".$images."")) {
				$images = "small_".$images."";
			}
			$size2 = @getimagesize("$path/$images");
			$widthimg = $size2[0];
			if ($size2[0] > $sizecatnewshomeimg) { $widthimg = $sizecatnewshomeimg; }
			$xtitle = stripslashes(check_html($row2['title'], "nohtml"));
			$story_pic = "<table border=\"0\" width=\"$widthimg\" cellpadding=\"0\" cellspacing=\"3\" align=\"$catnewshomeimg\">\n<tr>\n<td>\n<a href=\"modules.php?name=$module_name&op=viewst&sid=$sid\"><img border=\"0\" src=\"$path/$images\" width=\"$widthimg\" alt=\"$xtitle\"></a></td>\n</tr>\n<tr>\n<td align=\"center\">$imgtext</td>\n</tr>\n</table>\n";		
		}
		$notes = "";
		themeindex($aid, $time, $title, $hometext, $story_pic, $notes, $story_link, $com_link, $tot_hits, $a);
		$a++;
    }
    echo @generate_page($base_url, $all_page, $per_page, $page);
    echo "</td>\n";
    echo "</tr>\n</table>";
    include("footer.php");
}

function archive($catid,$pozit,$day,$month,$year) {
	global $module_name, $hourdiff, $sizecatnewshomeimg, $path, $adminfold, $adminfile, $catnewshomeimg, $newspagenum, $catimgnewshome, $db, $prefix, $multilingual, $currentlang ;
	$catid = intval($catid);
	if (($pozit > 3) || (!$day) || (strlen($day) > 2) || (!$month) || (strlen($month) > 2) || (!$year) || (strlen($year) > 4) || (strlen($catid) > 4)) { Header("Location: modules.php?name=$module_name");  exit; }

	if ($catid!=0) {
		$c = "catid='$catid' and";
		$v = "&catid=$catid&pozit=$pozit&day=$day&month=$month&year=$year";
	} else {
		$c = "";
		$v="&pozit=$pozit&day=$day&month=$month&year=$year";
	}
	if ($pozit == 1) {
		$pz = "time <= '$year-$month-$day 23:59:59'";
		$pzs = ""._DATENEWS."";
	} elseif ($pozit == 2) {
		$pz = "time >= '$year-$month-$day 00:00:00'";
		$pzs = ""._DATENEWS2."";
	} else {
		$pz = "time >= '$year-$month-$day 00:00:00' and time <= '$year-$month-$day 23:59:59'";
		$pzs = ""._DATENEWS3."";
	}
	$p ="$c $pz";
    if ($multilingual == 1) { $querylang = "AND (alanguage='$currentlang' OR alanguage='')"; } else { $querylang = ""; }
    $numf = $db->sql_fetchrow($db->sql_query("SELECT COUNT(*) FROM ".$prefix."_stories WHERE $p $querylang"));
	$page = ( isset($_GET['page']) ) ? intval($_GET['page']) : 0;
	$all_page = ( $numf[0] ) ? $numf[0] : 1;
	$per_page = intval($newspagenum);
	$base_url = "modules.php?name=$module_name&op=viewtop&topicid=$topicid";
    $result = $db->sql_query("SELECT * FROM ".$prefix."_stories WHERE $p $querylang order by sid DESC LIMIT $page,$per_page");
	include("header.php");
	echo"<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n<tr>\n<td valign=\"top\">";
	$numrows = $db->sql_numrows($result);
	if ($numrows == 0) {
	OpenTable();
	echo "<center><br><br><b>"._NONEWSDATE."!</b><br><br></center>";
	CloseTable();
    } else {
	OpenTable();
 	if (($catid!='') AND ($catid!=0)) {
	$result_m = $db->sql_query("SELECT title FROM ".$prefix."_stories_cat WHERE catid='$catid'");
	$row_m = $db->sql_fetchrow($result_m);
	$title_m = stripslashes(check_html($row_m['title'], "nohtml"));
	echo "<center>"._NEWSDATE." <b>$title_m</b> $pzs: $day.$month.$year</center>";
	} else {
	echo "<center><b>"._NEWSDATE2." $pzs: $day.$month.$year</b></center>";
	}
	CloseTable();
	echo "<br>";
	$a=0;
    while ($row = $db->sql_fetchrow($result)) {
	$sid = intval($row['sid']);
	$catid = intval($row['catid']);
	$aid = stripslashes($row['aid']);
	$title = stripslashes(check_html($row['title'], "nohtml"));
	$time = formatTimestamp($row['time']);
	$hometext = stripslashes($row['hometext']);
	$bodytext = stripslashes($row['bodytext']);
	$images = $row['images'];
	$imgtext = stripslashes(check_html($row['imgtext'], "nohtml"));
	$comments = stripslashes($row['comments']);
	$counter = intval($row['counter']);
	$notes = stripslashes($row['notes']);
	$acomm = intval($row['acomm']);
	if ($catid > 0) {
            $result2 = $db->sql_query("SELECT title, catimage FROM ".$prefix."_stories_cat WHERE catid='$catid'");
            $row2 = $db->sql_fetchrow($result2);
            $cattitle = stripslashes(check_html($row2['title'], "nohtml"));
            $catimage = $catimage = $row2['catimage'];
            if ($catimgnewshome == 1) {
    	if ($catimage == "") { $catimage = "AllTopics.gif"; }
    	if ($catnewshomeimg == "right") { $fl = "left"; }
    	if ($catnewshomeimg == "left") { $fl = "right"; }
    	$size2 = @getimagesize("images/cat/$catimage");
    	$title = "<a href=\"modules.php?name=News&op=viewcat&catid=$catid\" title=\"$cattitle\"><img border=\"0\" src=\"images/cat/$catimage\" width=\"$size2[0]\" style=\"float: $fl\"></a> <a href=\"modules.php?name=News&op=viewst&sid=$sid\">$title</a>";
            } else {
    	$title = "<a href=\"modules.php?name=News&op=viewcat&catid=$catid\">$cattitle</a>: <a href=\"modules.php?name=News&op=viewst&sid=$sid\">$title</a>";
            }
        }
        $story_link = "";
        if ($bodytext != "") {
        $story_link = "<a href=\"modules.php?name=News&op=viewst&sid=$sid\"><img src='images/more.gif' border='0'  alt=\""._READMORE."\" style=\"float: right\"></a>";
        }
        $print = "";
        $com_link = "";
        if (defined('IS_ADMMOD')) {
        $com_link .= " ("._COMMENTSQ.": $comments  | ";
        $tot_hits = ""._TOTHITS.": $counter | <a href=\"".$adminfold."/".$adminfile.".php?op=EditStory&sid=$sid\">"._EDIT."</a> | <a href=\"".$adminfold."/".$adminfile.".php?op=RemoveStory&sid=$sid\">"._DELETE."</a>)";
        }
        
        if ($images != "" AND file_exists("".$path."/".$images."")) {
			if(file_exists("".$path."/small_".$images."")) {
				$images = "small_".$images."";
			}
			$size2 = @getimagesize("$path/$images");
			$widthimg = $size2[0];
			if ($size2[0] > $sizecatnewshomeimg) { $widthimg = $sizecatnewshomeimg; }
			$xtitle = stripslashes(check_html($row['title'], "nohtml"));
			$story_pic = "<table border=\"0\" width=\"$widthimg\" cellpadding=\"0\" cellspacing=\"3\" align=\"$catnewshomeimg\">\n<tr>\n<td>\n<a href=\"modules.php?name=$module_name&op=viewst&sid=$sid\"><img border=\"0\" src=\"$path/$images\" width=\"$widthimg\" alt=\"$xtitle\"></a></td>\n</tr>\n<tr>\n<td align=\"center\">$imgtext</td>\n</tr>\n</table>\n";		
	} else {
		$story_pic = "";
	}
        $notes = "";
        themeindex($aid, $time, $title, $hometext, $story_pic, $notes, $story_link, $com_link, $tot_hits, $a);
        $a++;
    }
    echo @generate_page($base_url, $all_page, $per_page, $page);
	echo "<br><br>";
}
echo "<br>";
OpenTable();
echo"<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n"
  . "<form method=\"POST\" action=\"modules.php?name=$module_name\">\n"
  . "<tr>\n<td align=\"center\"><b>"._POISK."</b>\n<br><br><select name=\"pozit\">\n"
  . "<option name=\"pozit\" value=\"1\" selected>"._POZIT1."</option>\n"
  . "<option name=\"pozit\" value=\"2\">"._POZIT2."</option>\n"
  . "<option name=\"pozit\" value=\"3\">"._POZIT3."</option>\n"  
  . "</select> <select name=\"day\">\n";
for($i=1;$i <= 31;$i++) {
		echo "<option value=\"".str_pad($i, 2, "0", STR_PAD_LEFT)."\"";
		if($i == date("d",time()+$hourdiff * 60)) { echo " selected"; }
		echo ">".str_pad($i, 2, "0", STR_PAD_LEFT)."</option>\n";
}
echo"</select>\n<select name=\"month\">\n";
for($i=1;$i <= 12;$i++) {
		echo "<option value=\"".str_pad($i, 2, "0", STR_PAD_LEFT)."\"";
		if($i == date("m",time()+$hourdiff * 60)) { echo " selected"; }
		echo ">".str_pad($i, 2, "0", STR_PAD_LEFT)."</option>\n";
}
echo"</select>\n<select name=\"year\">\n";
$z = date("Y",time()+$hourdiff * 60);
	for($i=$z;$i >= $z-4;$i--) {
		echo "<option value=\"$i\"";
		if($i == $z) { echo " selected"; }
		echo ">$i</option>\n";
	}
echo"</select>\n<br>\n<select name=\"catid\">\n";
echo"<option name=\"catid\" value=\"\">"._ALLCATEGORIES."</option>\n";
$sql = "SELECT catid, parentid, title FROM ".$prefix."_stories_cat order by parentid, weight";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) {
$catid = $row[catid];
$title = $row[title];
$parentid = $row['parentid'];
if($parentid != 0) {
	list($ptitle) = $db->sql_fetchrow($db->sql_query("select title from ".$prefix."_stories_cat where catid='$parentid'"));
    $title = "$ptitle &raquo; $title";
}
echo"<option name=\"catid\" value=\"$catid\">$title</option>\n";
}
echo"</select>\n<input type=\"hidden\" name=\"op\" value=\"archive\"><input type=\"submit\" value=\""._SEARCH."\"></td>\n"
  . "</tr>\n</form>\n</table>\n";
CloseTable();
    echo "</td>\n";
    echo "</tr>\n</table>";
include("footer.php");
}

switch($op) {
	
	case "viewst":
		viewst();
		break;
	
	case "showcomm":
		showcomm($sid);
		break;
	
	case "viewcat":
		viewcat($catid);
		break;
		
	case "viewtop":
		viewtop($topicid);
		break;
		
	case "archive":
		archive($catid,$pozit,$day,$month,$year);
		break;

    default:
        main();
        break;

}

?>